package com.hyt.it.ogt.kq.main.controller.bm;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.common.utils.KqStringUtils;
import com.hyt.it.ogt.kq.service.bm.model.entity.SubjectExamHistory;
import com.hyt.it.ogt.kq.service.bm.service.ISubjectExamHistoryService;
import com.hyt.model.PageParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liteng
 * @since 2020-06-18
 */
@RestController
@Api(tags = "14.管理端：科目历史绑定考试接口", value = "科目绑定考试接口")
@ApiSort(value = 14)
@RequestMapping("/bm/subject-exam-history")
public class SubjectExamHistoryController {

	@Autowired
	ISubjectExamHistoryService iSubjectExamHistoryService;

	@ApiOperation(value = "14.1.1 查询分页数据", notes = "20000:成功,31010136:查询失败，异常")
	@ApiOperationSort(value = 1)
	@RequestMapping(value = "/queryPage", method = RequestMethod.GET)
	public Object queryPage(PageParam<SubjectExamHistory> pageParam, SubjectExamHistory subjectExamHistory) {
		Page<SubjectExamHistory> page = pageParam;
		try {
			QueryWrapper<SubjectExamHistory> wrapper = new QueryWrapper<SubjectExamHistory>();
			if (KqStringUtils.isNotBlank(subjectExamHistory.getProjectId())) {
				wrapper.eq("project_id", subjectExamHistory.getProjectId());
			}
			if (KqStringUtils.isNotBlank(subjectExamHistory.getSubjectId())) {
				wrapper.eq("subject_id", subjectExamHistory.getSubjectId());
			}
			wrapper.orderByDesc("create_date");
			page = iSubjectExamHistoryService.page(page, wrapper);
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31010136).data(page).build();
		}

	}

	@ApiOperation(value = "14.1.2 查询列表", notes = "20000:成功,31010136:查询失败，异常")
	@ApiOperationSort(value = 2)
	@RequestMapping(value = "/queryList", method = RequestMethod.GET)
	public Object queryList(String projectId, String subjectId) {
		try {
			QueryWrapper<SubjectExamHistory> wrapper = new QueryWrapper<SubjectExamHistory>();
			if (KqStringUtils.isNotBlank(projectId)) {
				wrapper.eq("project_id", projectId);
			}
			if (KqStringUtils.isNotBlank(subjectId)) {
				wrapper.eq("subject_id", subjectId);
			}
			wrapper.orderByDesc("create_date");
			List<SubjectExamHistory> list = iSubjectExamHistoryService.list(wrapper);
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(list).build();
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31010136).build();
		}

	}
}
